import React, { Component } from 'react';
import { Modal } from 'antd';
import { connect } from 'dva';

@connect(({ component }) => ({
  isRightDrawOpen: component.isRightDrawOpen,
}))
export default class AdModal extends Component {
  componentWillReceiveProps(nextProps) {
    const { visible, dispatch, isRightDrawOpen } = nextProps;
    let isRightDrawOtherOpen = false;
    if (this.props.visible !== visible) {
      if (visible) {
        isRightDrawOtherOpen = true;
      }
      if (!isRightDrawOpen) return;
      dispatch({
        type: 'component/setRightDrawValue',
        payload: {
          isRightDrawOtherOpen,
        },
      });
    }
  }

  render() {
    const { children, ...rest } = this.props;
    return (
      <Modal width={620} destroyOnClose={true} style={{ top: 20 }} {...rest}>
        {children}
      </Modal>
    );
  }
}
